package ilvonen.ihstatistics;

import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class SettingActivity extends Activity {

	private final Context context = this;
	private EditText _etUser;
	private EditText _etPass;
	private Button _bSave;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_setting);
		_etUser = (EditText)findViewById(R.id.etUsername);
		_etPass = (EditText)findViewById(R.id.etPassword);
		_bSave = (Button)findViewById(R.id.btnSaveSettings);
		
		SetSettings();
		_bSave.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				SharedPreferences settings = getSharedPreferences("UserInfo", 0);
				SharedPreferences.Editor editor = settings.edit();
				editor.putString("Username",_etUser.getText().toString());
				editor.putString("Password",_etPass.getText().toString());
				editor.commit();
			}
		});
	}

	private void SetSettings() {
		// TODO Auto-generated method stub
		SharedPreferences settings = getSharedPreferences("UserInfo", 0);
		_etUser.setText(settings.getString("Username", "").toString());
		_etPass.setText(settings.getString("Password", "").toString());
	}
}
